package com.znyj.servlet.dao;

import com.znyj.servlet.entity.MerchantEntity;
import com.znyj.servlet.sqlHelper.SqlProvider;
import com.znyj.servlet.sqlHelper.SqlRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by gaoliwei02 on 2017/9/18.
 */
@Repository
public interface MerchantDao {
    public static final String SELECT_KEYS = " " +
            "id," +
            "poiid," +
            "bd_name," +
            "register_time," +
            "phone_number," +
            "role_permission," +
            "device_list," +
            "open_info," +
            "wifi," +
            "city_area," +
            "merchant_name," +
            "merchant_address," +
            "usage_fee";

    public static final String INSERT_KEYS = " " +
            "poiid," +
            "bd_name," +
            "register_time," +
            "phone_number," +
            "role_permission," +
            "device_list," +
            "open_info," +
            "wifi," +
            "city_area," +
            "merchant_name," +
            "merchant_address," +
            "usage_fee";

    public static final String INSERT_VALUES = " " +
            "#{poiid}," +
            "#{bdName}," +
            "#{registerTime}," +
            "#{phoneNumber}," +
            "#{rolePermission}," +
            "#{deviceList}," +
            "#{openInfo}," +
            "#{wifi}," +
            "#{cityArea}," +
            "#{merchantName}," +
            "#{merchantAddress}," +
            "#{usageFee}";

    @Insert("insert into cdb_merchant (" + INSERT_KEYS + ") values (" + INSERT_VALUES + ") ")
    public int insert(MerchantEntity entity);

    @Update("update cdb_merchant set " +
            "phone_number=#{phoneNumber}," +
            "device_list=#{deviceList}," +
            "open_info=#{openInfo}," +
            "wifi=#{wifi}, " +
            "city_area=#{cityArea}, " +
            "wifi=#{wifi}, " +
            "merchant_name=#{merchantName}, " +
            "merchant_address=#{merchantAddress}, " +
            "usage_fee=#{usageFee} " +
            "where poiid=#{poiid}")
    public int update(MerchantEntity entity);

    @Select("select * from cdb_merchant where poiid=#{poiid}")
    public MerchantEntity findByPoiid(@Param("poiid") int poiid);

    @Select("select poiid from cdb_merchant order by poiid desc limit 1")
    public long findNewestPoiid();

    @SelectProvider(type = SqlProvider.class, method = "query")
    public List<MerchantEntity> query(SqlRequest request);

    @SelectProvider(type = SqlProvider.class, method = "count")
    public int count(SqlRequest request);

    @SelectProvider(type = SqlProvider.class, method = "findBindMerchant")
    public List<MerchantEntity> findBindMerchant(String deviceId);
}
